<template>
  <el-submenu ref="subMenu" :index="handlePath(item.path)" :popper-append-to-body="false"
    :class="'el-menu-level-' + item.level">
    <template slot="title">
      <!-- <vab-icon
        v-if="item.meta && item.meta.icon"
        :icon="['fas', item.meta.icon]"
        class="vab-fas-icon"
      />
      <vab-remix-icon
        v-if="item.meta && item.meta.remixIcon"
        :icon-class="item.meta.remixIcon"
        class="vab-remix-icon"
      /> -->
      <svg-icon v-if="item.meta.icon" :iconClass="item.meta.icon"></svg-icon>
      <span>{{ item.meta.title }}</span>
    </template>
    <slot />
  </el-submenu>
</template>

<script>
import { isExternal } from '@/utils/validate'
import svgIcon from '../../VabColorfullIcon'
import path from 'path'

export default {
  name: 'VabSubmenu',
  components: { svgIcon },
  props: {
    routeChildren: {
      type: Object,
      default() {
        return null
      },
    },
    item: {
      type: Object,
      default() {
        return null
      },
    },
    fullPath: {
      type: String,
      default: '',
    },
  },
  methods: {
    handlePath(routePath) {
      if (isExternal(routePath)) {
        return routePath
      }
      if (isExternal(this.fullPath)) {
        return this.fullPath
      }
      return path.resolve(this.fullPath, routePath)
    },
  },
}
</script>
